
import Pure from 'pure-frontend';

/* SOURCE-CODE-START */

"use strict";

Pure.app.viewMain('example1', function (scope, view) {
  // 定义校验规则
  view.$find('form').validate({
    rules: {
      id: 'required',
      exampleName: 'required'
    },
    messages: {
      id: '${t("ui.example.example1.validation.inputId")}',
      exampleName: '${t("ui.example.example1.validation.inputExampleName")}'
    }
  });

  view.$ui('checkBtn').on('click', function () {
    var checkResult = view.$find('form').valid();

    if (checkResult) {
      var model = view.getDataModel();
      var data = model.getData('*');

      // 检查数据
      view.callService('api/example/checkData', data)
        .waitResult(function (result, textStatus, jqXHR) {
          if (result.success) {
            Pure.app.showMessage('${t("ui.example.example1.msg.checkSuccess")}');
          } else {
            Pure.app.showError('${t("ui.example.example1.msg.checkFailed")}');
          }
        });
    }
  });


});

/* SOURCE-CODE-END */
